package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.Apply;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.util.PrettyPrintDisplay;

@SuppressWarnings("serial")
public class WffApply implements WffBuildOp
{
  private final WffBuildOp argOps[];
  private final WffBuildOp op;

  public WffApply(WffBuildOp op, WffBuildOp args[])
  {
    this.argOps = args;
    this.op = op;
  }

  @Override
  public IAbstract build(IAbstract[] env, Location loc, WffEngine engine)
  {
    IAbstract args[] = new IAbstract[argOps.length];
    for (int ix = 0; ix < argOps.length; ix++)
      args[ix] = argOps[ix].build(env, loc, engine);
    return new Apply(loc, op.build(env, loc, engine), args);
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    op.prettyPrint(disp);
    disp.append("(");
    disp.prettyPrint(argOps, ", ");
    disp.append(")");
  }
}
